fix: #261 add support for other models that could produce JSON output in text content #532
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This pull request resolves #261
Here are the actual request and response data in the scenario mentioned in the issue:
request
{ "tools": [], "prompt": [ { "role": "system", "content": "You are a helpful assistant\n\nYou must respond with a JSON object that matches this schema:\n{\n \"type\": \"object\",\n \"properties\": {\n \"content\": {\n \"type\": \"string\",\n \"description\": \"Markdown formatted content \"\n }\n },\n \"required\": [\n \"content\"\n ],\n \"additionalProperties\": false,\n \"$schema\": \"http://json-schema.org/draft-07/schema#\"\n}\nReturn only valid JSON without code fences or extra commentary." }, { "role": "user", "content": [ { "type": "text", "text": "Write a haiku about programming." } ], "providerOptions": {} } ], "responseFormat": { "type": "json", "name": "output", "schema": { "type": "object", "properties": { "content": { "type": "string", "description": "Markdown formatted content " } }, "required": [ "content" ], "additionalProperties": false, "$schema": "http://json-schema.org/draft-07/schema#" } } }response
{ "responseId": "gen-1758930715-v132zfskAXPfAUDr5trQ", "usage": { "requests": 1, "inputTokens": 139, "outputTokens": 37, "totalTokens": 176, "inputTokensDetails": [], "outputTokensDetails": [] }, "output": [ { "type": "message", "content": [ { "type": "output_text", "text": "{\n \"content\": \"Code flows like water,\\nBugs hide in silent shadows—\\nDebug, breathe, repeat.\"\n}" } ], "role": "assistant", "status": "completed", "providerData": { "openrouter": { "provider": "Google", "usage": { "promptTokens": 139, "completionTokens": 37, "totalTokens": 176, "promptTokensDetails": { "cachedTokens": 0 }, "completionTokensDetails": { "reasoningTokens": 0 }, "costDetails": { "upstreamInferenceCost": 0 } } } } } ], "providerData": { "content": [ { "type": "text", "text": "{\n \"content\": \"Code flows like water,\\nBugs hide in silent shadows—\\nDebug, breathe, repeat.\"\n}" } ], "finishReason": "stop", "usage": { "inputTokens": 139, "outputTokens": 37, "totalTokens": 176, "reasoningTokens": 0, "cachedInputTokens": 0 }, "warnings": [], "providerMetadata": { "openrouter": { "provider": "Google", "usage": { "promptTokens": 139, "completionTokens": 37, "totalTokens": 176, "promptTokensDetails": { "cachedTokens": 0 }, "completionTokensDetails": { "reasoningTokens": 0 }, "costDetails": { "upstreamInferenceCost": 0 } } } }, "request": { "body": { "model": "anthropic/claude-sonnet-4", "response_format": { "type": "json_schema", "json_schema": { "schema": { "type": "object", "properties": { "content": { "type": "string", "description": "Markdown formatted content " } }, "required": [ "content" ], "additionalProperties": false, "$schema": "http://json-schema.org/draft-07/schema#" }, "strict": true, "name": "output" } }, "messages": [ { "role": "system", "content": "You are a helpful assistant\n\nYou must respond with a JSON object that matches this schema:\n{\n \"type\": \"object\",\n \"properties\": {\n \"content\": {\n \"type\": \"string\",\n \"description\": \"Markdown formatted content \"\n }\n },\n \"required\": [\n \"content\"\n ],\n \"additionalProperties\": false,\n \"$schema\": \"http://json-schema.org/draft-07/schema#\"\n}\nReturn only valid JSON without code fences or extra commentary." }, { "role": "user", "content": "Write a haiku about programming." } ] } }, "response": { "id": "gen-1758930715-v132zfskAXPfAUDr5trQ", "modelId": "anthropic/claude-sonnet-4", "headers": { "access-control-allow-origin": "*", "cf-ray": "9856ac076f8f986e-NRT", "connection": "keep-alive", "content-encoding": "gzip", "content-type": "application/json", "date": "Fri, 26 Sep 2025 23:51:56 GMT", "permissions-policy": "payment=(self \"https://checkout.stripe.com\" \"https://connect-js.stripe.com\" \"https://js.stripe.com\" \"https://*.js.stripe.com\" \"https://hooks.stripe.com\")", "referrer-policy": "no-referrer, strict-origin-when-cross-origin", "server": "cloudflare", "transfer-encoding": "chunked", "vary": "Accept-Encoding", "x-content-type-options": "nosniff" } } } }code